package com.qhw.jdbc;

import javax.sound.midi.Soundbank;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class AppJdbcSelect {
    public static void main(String[] args) throws Exception {
        //1.加载驱动类
        Class.forName("com.mysql.cj.jdbc.Driver");
        String url = "jdbc:mysql://localhost:3306/test?useSSL=false";
        String name = "root";
        String password = "password";

        //2.获取连接
        Connection connection = DriverManager.getConnection(url, name, password);

        //3.创建陈述对象
        Statement statement = connection.createStatement();

        //4.执行查询
        String sql = "select * from user";
        ResultSet resultSet = statement.executeQuery(sql);

        //5.输出结果
        while (resultSet.next()) {
            System.out.println(resultSet.getString(1) + " " + resultSet.getString(2));
        }
    }
}
